<?php

namespace App\Pockets;

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Collection;

class ReLengthAwarePaginator extends LengthAwarePaginator
{
    protected $extra_btn;

    /**
     * Create a new paginator instance.
     *
     * @param  mixed  $items
     * @param  int  $total
     * @param  int  $perPage
     * @param  int|null  $currentPage
     * @param  array  $options (path, query, fragment, pageName)
     * @return void
     */
    public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
    {
        parent::__construct($items, $total, $perPage, $currentPage, $options);
        $this->extra_btn = $this->extra_btn ? : [];
    }


    /**
     * Get the instance as an array.
     *
     * @return array
     */
    public function toArray()
    {
        $rs = parent::toArray();
        $rs['extra_btn'] = $this->extra_btn();
        return $rs;
    }

    public function extra_btn()
    {
        return $this->extra_btn;
    }

    public function currPageUrl()
    {
        return $this->url($this->currentPage());

    }

    public function exitCurrPageUrl()
    {
        if(isset($this->extra_btn()['reset_first_page_start_time'])) {
            $start_time = $this->extra_btn()['reset_first_page_start_time'];
            $query = $this->query;
            $query['release_time']['start'] = $start_time;
            $this->query = $query;
        }
        $url = $this->url($this->currentPage());
        return $url;

    }

}
